package com.yyx.pojo;


import com.yyx.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class test {
/*    @Test
    public void test() throws IOException {
        InputStream resource = Resources.getResourceAsStream("mybatis-Config.bak.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
        SqlSession session = sqlSessionFactory.openSession();
        User user = session.selectOne("UserMapper.queryUser");
        System.out.println(user);
    }*/

    @Test
    public void test2() throws IOException {
//         String str ="mybatis-Config.xml";
//        指定配置文件并读取配置文件
//        InputStream resource= Resources.getResourceAsStream(str);
        InputStream resource = Resources.getResourceAsStream("mybatis-Config.xml");
//        创建mybatis工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
//        利用工厂对象，获取SqlSession对象
        SqlSession session = sqlSessionFactory.openSession();
//利用SqlSession对象，获取UserMapper的动态代理对象
        UserMapper userMapper = session.getMapper(UserMapper.class);
//        调用接口中的方法
        User userById = userMapper.findUserById();
        System.out.println(userById);
    }


}
